home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Light ROM 1
/
LIGHT-ROM 1 (Amiga Library Services)(1994).iso
/
ffdisks
/
d978.lha
/
NewEdit
/
Source
/
ClipBoard.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-03
|
6KB
|
221 lines
/*----------------------------------------------------------------------------
File : ClipBoard.c
Projekt: NewEdit
Inhalt : init_iffparse()
close_iffparse()
read_clip()
write_clip()
Version: 1.5
Datum : 16. August 1992
Autor : Uwe Röhm
Adresse: Wörthstr. 18, W-8390 Passau
Bemerkung:
Funktionen zum Öffnen, Lesen, Schreiben und Schliessen des Clipboards
Unit 0 mittels der iffparse.library.
----------------------------------------------------------------------------*/
#include <libraries/iffparse.h>
/* ------------------------ Prototypes & Pragmas ------------------------ */
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/iffparse_protos.h>
#ifdef LATTICE
#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/iffparse_pragmas.h>
#endif
/* --------------------------- eigene Defines --------------------------- */
#define NO_IFFHANDLE "Couldn't allocate IFFHandle\n."
#define NO_CLIPHANDLE "Couldn't open Clipboard.\n"
#define ERROR_LIBRARY "Can't open library '%s' V %ld.\n"
#define IFFNAME "iffparse.library"
#define ID_FTXT MAKE_ID('F','T','X','T')
#define ID_CHRS MAKE_ID('C','H','R','S')
/* ---------------------------- globale Vars ---------------------------- */
extern struct Library *DOSBase;
extern struct Library *SysBase;
struct Library *IFFParseBase = NULL;
struct IFFHandle *Iff = NULL;
/****** init_iffparse() *****************************************************
*
* NAME
* init_iffparse -- initialises iffparse.library for clipboard unit 0
* SYNOPSIS
* success = init_iffparse ()
*
* BOOL init_iffparse ( void );
* FUNCTION
* Allocates and initialises IFFHandle structure for Read/Write
* to/from clipboard.device unit 0. Must be matched with call to
* close_iffparse().
* INPUTS
*
* RESULT
* success - TRUE if all done correct, else FALSE
* DATE
* 16 Aug 1992
* SEE ALSO
* close_iffparse()
*****************************************************************************
*/
BOOL init_iffparse ( void )
{
if ( (IFFParseBase = OpenLibrary(IFFNAME, 37L)) != NULL )
{
if ( (Iff = AllocIFF()) != NULL )
{
if ( (Iff->iff_Stream = (ULONG) OpenClipboard(0)) != NULL )
{
InitIFFasClip (Iff);
return TRUE;
} /* if OpenClipboard() */
else
PutStr ( NO_CLIPHANDLE );
} /* if AllocIFF () */
else
PutStr ( NO_IFFHANDLE );
} /* if OpenLibrary() */
else
Printf ( ERROR_LIBRARY, IFFNAME, 37 );
return FALSE;
}
/****** close_iffparse() ****************************************************
*
* NAME
* close_iffparse -- frees space allocated by init_iffparse
* SYNOPSIS
* close_iffparse ()
*
* void close_iffparse ( void );
* FUNCTION
* Opposite to init_iffparse().
* INPUTS
*
* RESULT
*
* DATE
* 18. April 1992
* SEE ALSO
* init_iffparse()
*****************************************************************************
*/
void close_iffparse ( void )
{
if (Iff != NULL && Iff->iff_Stream != NULL)
CloseClipboard ((void *) Iff->iff_Stream);
if (Iff != NULL)
FreeIFF (Iff);
if (IFFParseBase != NULL)
CloseLibrary (IFFParseBase);
}
/****** read_clip() *********************************************************
*
* NAME
* read_clip -- read text from clipboard unit 0 into specified buffer
* SYNOPSIS
* Length = read_clip ( buffer, buflen )
*
* ULONG read_clip ( UBYTE *, ULONG )
* FUNCTION
* Fills the specified buffer with the text from clipboard unit 0
* upto buflen characters. The number of read chars are returned
* (may be 0, if clipboard is empty or contains no text).
* IMPORTANT:
* The iffparse.library must be open and the global IFFHandle Iff must
* be initialised. Use init_iffparse() before!!!
* INPUTS
* buffer - buffer to be filled
* buflen - length of the given buffer
* RESULT
* Length - actual read characters,
* 0 if clipboard was empty or contained no-text
* DATE
* 12. August 1992
* SEE ALSO
* write_clip() init_iffparse()
*****************************************************************************
*/
ULONG read_clip ( UBYTE *buffer, ULONG buflen )
{
struct ContextNode *cn;
ULONG length = 0;
OpenIFF (Iff, IFFF_READ);
if ( StopChunk(Iff, ID_FTXT, ID_CHRS) == 0 )
{
while (ParseIFF (Iff, IFFPARSE_SCAN) == 0 )
{
cn = CurrentChunk(Iff);
if ( (cn) && (cn->cn_Type == ID_FTXT) && (cn->cn_ID == ID_CHRS) )
{
length = ReadChunkBytes(Iff, buffer, buflen);
break;
} /* if cn ... */
} /* while ParseIff() */
} /* if stopchunk() */
CloseIFF(Iff);
return length;
}
/****** write_clip() ********************************************************
*
* NAME
* write_clip -- write text into clipboard unit 0
* SYNOPSIS
* write_clip ( buffer, length )
*
* void write_clip ( UBYTE *, ULONG )
* FUNCTION
* Writes 'length' characters from the specified buffer into clipboard
* unit 0.
* IMPORTANT:
* The iffparse.library must be open and the global IFFHandle Iff must
* be initialised. Use init_iffparse() before!!!
* INPUTS
* buffer - buffer to be written
* length - number of chars to be written
* RESULT
*
* DATE
* 12. August 1992
* SEE ALSO
* read_clip() init_iffparse()
*****************************************************************************
*/
void write_clip ( UBYTE *data, ULONG length )
{
OpenIFF (Iff, IFFF_WRITE);
if( PushChunk(Iff, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN) == 0 )
{
if( PushChunk(Iff, 0, ID_CHRS, IFFSIZE_UNKNOWN) == 0 )
{
WriteChunkBytes(Iff, data, length);
PopChunk (Iff);
} /* if PushChunk() */
PopChunk (Iff);
} /* if PushChunk() */
CloseIFF(Iff);
}